package statistics

import (
	"data/config"
	"data/view/paper"
	"public/mysqldb"
)

//获取题目答题情况
func GetQuestAnswerData(quest_no, right_answer string) (right_count, answer_count int, right_rate float64) {
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var r []paper.Exam_detail_tbl
	orm.Where("quest_no = ?", quest_no).Find(&r)
	if len(r) > 0 {
		for _, v := range r {
			if v.Answer == right_answer {
				right_count++
			}
		}
	}
	answer_count = len(r)
	right_rate = float64(right_count) / float64(answer_count)
	return
}

//获取某一选项答题情况
func GetOneOptionData(quest_no string, answer_count int, options []string) (result []OptionRate) {
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	if len(options) > 0 {
		for _, v := range options {
			var info []paper.Exam_detail_tbl
			orm.Where("quest_no = ? and answer = ?", quest_no, v).Find(&info)
			var t OptionRate
			t.Option = v
			t.Right_rate = float64(len(info)) / float64(answer_count)
			result = append(result, t)
		}
	}
	return
}
